/*
 * =====================================================================================
 *
 *       Filename:  cl_callback.hxx
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  03/27/2011 10:52:15 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Chen Ken (Ken), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#ifndef _CL_CALLBACK_HXX_
#define _CL_CALLBACK_HXX_

#include <functional>

namespace neo
{
typedef std::function<void()> CLCallbackFunctor;

class CLCallbackBase
{
public:
  virtual void operator()(void) const {}
  virtual ~CLCallbackBase() = 0;
}; 

template<typename T>
class CLCallback: public CLCallbackBase
{
public:
  typedef void (T::*MemFunc)();
  CLCallback(T& t, MemFunc f)
  	: m_t(&t), m_f(f) 
  {
  }

  virtual void operator()(void) const 
  {
  	(m_t->*m_f)();
  }

private:
  T* m_t;
  MemFunc m_f;
};

template<typename T>
CLCallback<T> clMakeCallback(T& t, void (T::*f)())
{
  return CLCallback<T>(t, f);
}

} // neo

#endif //_CL_CALLBACK_HXX_

